/**
 * @author https://vue-admin-beautiful.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)

// 解决重复路由报错
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },

]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    hidden: true,
    children: [
      {
        path: '/index',
        name: '/index',
        component: () => import('@/views/index/welcome'),
        meta: {
          title: '首页',
          name: '首页',
          icon: 'home',
          remixIcon: 'home',
          affix: true,
          permissions: ['drama', 'duser'],
        },
      },
    ],
  },
  {
    path: '/overview',
    component: Layout,
    redirect: '/overview',
    children: [
      {
        path: '/overview',
        name: '/overview',
        component: () => import('@/views/dep/index'),
        meta: {
          title: '票证总览',
          name: '票证总览',
          icon: 'pie-chart-2-line',
          remixIcon: 'user-2-line',
          affix: false,
          permissions: ['drama', 'duser'],
        },
      },
    ],
  },

  // 签章管理
  {
    path: '/signature',
    component: Layout,
    redirect: '/signature/signature',
    // 是否默认打开
    // alwaysShow: true,
    meta: {
      title: '签章管理',
      name: '签章管理',
      remixIcon: 'contacts-book-line',
      icon: 'contacts-book-line',
      permissions: ['drama'],
    },
    children: [
      {
        path: '/signature/signature',
        name: '/signature/signature',
        component: () => import('@/views/dep/signatureManagement/signature'),
        meta: {
          title: '电签印章管理',
          name: '电签印章管理',
          icon: 'contacts-book-line',
          affix: false,
          remixIcon: 'contacts-book-line',
          permissions: ['drama'],
        },
      },
      {
        path: '/signature/certificate',
        name: '/signature/certificate',
        component: () => import('@/views/dep/signatureManagement/certificate'),
        meta: {
          title: '查询数字证书',
          name: '查询数字证书',
          icon: 'folder-chart-line',
          affix: false,
          remixIcon: 'folder-chart-line',
          permissions: ['drama'],
        },
      }
    ],
  },

  // 票证入档
  {
    path: '/manualSignature',
    component: Layout,
    redirect: '/manualSignature/manualSignature',
    // 是否默认打开
    // alwaysShow: true,
    meta: {
      title: '票证入档',
      name: '票证入档',
      remixIcon: 'organization-chart',
      icon: 'organization-chart',
      permissions: ['drama'],
    },
    children: [
      {
        path: '/manualSignature/manualSignature',
        name: '/manualSignature/manualSignature',
        component: () => import('@/views/dep/putFile/manualSignature'),
        meta: {
          title: '手动签章入档',
          name: '手动签章入档',
          icon: 'organization-chart',
          affix: false,
          remixIcon: 'organization-chart',
          permissions: ['drama'],
        },
      },
      {
        path: '/manualSignature/automaticSignature',
        name: '/manualSignature/automaticSignature',
        component: () => import('@/views/dep/putFile/automaticSignature'),
        meta: {
          title: '自动签章入档',
          name: '自动签章入档',
          icon: 'robot-2-fill',
          affix: false,
          remixIcon: 'robot-2-fill',
          permissions: ['drama'],
        },
      }
    ],
  },


  // 归档管理
  {
    path: '/archive',
    component: Layout,
    redirect: '/archive/archive',
    // 是否默认打开
    // alwaysShow: true,
    meta: {
      title: '归档管理',
      name: '归档管理',
      remixIcon: 'arrow-down-box-fill',
      icon: 'arrow-down-box-fill',
      permissions: ['drama'],
    },
    children: [
      {
        path: '/archive/archive',
        name: '/archive/archive',
        component: () => import('@/views/dep/archive/index'),
        meta: {
          title: '目录管理',
          name: '目录管理',
          icon: 'arrow-down-box-fill',
          affix: false,
          remixIcon: 'arrow-down-box-fill',
          permissions: ['drama'],
        },
      },
      {
        path: '/archive/interface',
        name: '/archive/interface',
        component: () => import('@/views/dep/archive/interface'),
        meta: {
          title: '数据接口',
          name: '数据接口',
          icon: 'links-line',
          affix: false,
          remixIcon: 'links-line',
          permissions: ['drama'],
        },
      }
    ],
  },

  // 系统设置
  {
    path: '/adminManagemen',
    component: Layout,
    redirect: '/admin/list',
    // 是否默认打开
    // alwaysShow: true,
    meta: {
      title: '用户管理',
      name: '用户管理',
      remixIcon: 'user-settings-line',
      icon: 'user-settings-line',
      permissions: ['drama'],
    },
    children: [
      {
        path: '/admin/list',
        name: '/admin/list',
        component: () => import('@/views/admin/index'),
        meta: {
          title: '用户列表',
          name: '用户列表',
          icon: 'user-2-line',
          affix: false,
          remixIcon: 'user-2-line',
          permissions: ['drama'],
        },
      }
    ],
  },

  // 设置
  {
    path: '/set',
    component: Layout,
    redirect: '/set/basic',
    // 是否默认打开
    // alwaysShow: true,
    meta: {
      title: '设置',
      name: '设置',
      remixIcon: 'settings-2-line',
      icon: 'settings-2-line',
      permissions: ['drama'],
    },
    children: [
      {
        path: '/set/basic',
        name: '/set/basic',
        component: () => import('@/views/set/setBasic'),
        meta: {
          title: '设置基本工序价格',
          name: '设置基本工序价格',
          icon: 'user-settings-line',
          affix: false,
          remixIcon: 'user-settings-line',
          permissions: ['drama'],
        },
      },
      {
        path: '/set/else',
        name: '/set/else',
        component: () => import('@/views/set/setElse'),
        meta: {
          title: '设置基本工序价格',
          name: '设置额外工序价格',
          icon: 'user-settings-line',
          affix: false,
          remixIcon: 'user-settings-line',
          permissions: ['drama'],
        },
      }
    ],
  },
  {
    path: '/error',
    component: EmptyLayout,
    redirect: 'noRedirect',
    name: 'Error',
    meta: { title: '错误页', icon: 'bug', permissions: ['admin'] },
    children: [
      {
        path: '401',
        name: 'Error401',
        component: () => import('@/views/401'),
        meta: { title: '401' },
      },
      {
        path: '404',
        name: 'Error404',
        component: () => import('@/views/404'),
        meta: { title: '404' },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
